﻿// <copyright file="CommunityRandomComments.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2009-4-13</date>
// <summary>Community Random Comments</summary>

namespace NYTimes
{
    using System;
    using System.ComponentModel;
    using System.Globalization;
    using System.Text;
    using NYTimes.Core;

    /// <summary>
    /// New York Times Community Random Comments API
    /// </summary>
    /// <remarks>
    /// <list type="table">
    /// <listheader>
    /// <term>Application Resource Key</term>
    /// <description>Key to add to application resources</description>
    /// </listheader>
    /// <item>
    /// <term>
    /// NYTCommunityKey
    /// </term>
    /// <description>Community API Key</description>
    /// </item>
    /// <item>
    /// <term>
    /// NYTCommunityQPS
    /// </term>
    /// <description>Rate Limiting (default 30 QPS)</description>
    /// </item>
    /// </list>
    /// </remarks>
    public class CommunityRandomComments : CommunityBase
    {
        #region Fields
        /// <summary>
        /// the count of items to return
        /// </summary>
        private int count;
        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the CommunityRandomComments class.
        /// </summary>
        public CommunityRandomComments()
        {
            this.Count = 50;
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the number of items to return
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">if the count is less than 1 or greater than 50.</exception>
        [Description("The number of community comments (50 max).")]
        public int Count 
        { 
            get
            {
                return this.count;
            }

            set
            {
                if (value < 1 || value > 50)
                {
                    throw new ArgumentOutOfRangeException("value", "Count must be between 1 and 50.");
                }

                this.count = value;

                this.FetchResults(true);
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Generate the URI string
        /// </summary>
        /// <returns>the Modified URI string</returns>
        public override string GenerateUriFragment()
        {
            var builder = new StringBuilder();

            builder.AppendFormat(CultureInfo.InvariantCulture, "random.xml?count={0}", this.Count);

            return builder.ToString();
        }
        #endregion
    }
}
